package com.ysd.crm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ysd.crm.dao.IModulesDao;
import com.ysd.crm.model.Modules;
import com.ysd.crm.util.EntityUtil;

@RestController
@RequestMapping("/modules")
public class ModulesController {

	@Resource
	private IModulesDao modulesDao;
	
	@RequestMapping("findAll")
	public Map findAll() {
		List<Modules> list = modulesDao.findAll();
		Map map = new HashMap();
		map.put("code", 0);
		map.put("msg", "操作成功");
		map.put("data", list);
		return map;
	}
	
	@RequestMapping("save")
	public void save(Modules module) {
		modulesDao.save(module);
	}
	
	@RequestMapping("delOne")
	public void delOne(int id) {
		modulesDao.deleteById(id);
	}
	
	//角色分配模块查询
	//查询所有模块，同时选中角色拥有模块
	//这里采用左外连接的形式实现
	@RequestMapping("findByRid")
	public Map getModulesByRid(int rid) {
		List<Object[]> list = modulesDao.findModulesByRid(rid);
		List<Modules> mList = EntityUtil.castEntity(list, Modules.class);
		Map map = new HashMap();
		map.put("code", 0);
		map.put("msg", "操作成功");
		map.put("data", mList);
		return map;
	}
	
}
